
package mongolo;

import Biblioteca.*;
import Servicios.*;
import java.util.ArrayList;
import javax.swing.JOptionPane;

public class ConsultaUsuarios extends javax.swing.JFrame {
    
    /** Creates new form ConsultaUsuarios */
    public ConsultaUsuarios() {
        initComponents();
        this.setDefaultCloseOperation(javax.swing.JFrame.HIDE_ON_CLOSE);
    }
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        usuaIdjComboBox = new javax.swing.JComboBox();
        usuaNamejTex = new javax.swing.JTextField();
        usuaApe2jTex = new javax.swing.JTextField();
        usuaApejTex = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        SeleccionarUsuario = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
        });

        jLabel2.setText("nombre");

        jLabel1.setText("id");

        usuaIdjComboBox.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                usuaIdjComboBoxItemStateChanged(evt);
            }
        });

        jLabel3.setText("Apellido");

        SeleccionarUsuario.setText("Peliculas alquiladas (Usuario Actual)");
        SeleccionarUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SeleccionarUsuarioActionPerformed(evt);
            }
        });

        jLabel4.setText("Apellido 2");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(48, 48, 48)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel4)
                    .addComponent(jLabel3)
                    .addComponent(jLabel2)
                    .addComponent(jLabel1))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(usuaIdjComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(usuaApejTex)
                        .addComponent(usuaApe2jTex)
                        .addComponent(usuaNamejTex, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(110, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(68, Short.MAX_VALUE)
                .addComponent(SeleccionarUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 224, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(54, 54, 54))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(usuaIdjComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(usuaNamejTex, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(4, 4, 4)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(usuaApejTex, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(usuaApe2jTex, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(SeleccionarUsuario)
                .addContainerGap(61, Short.MAX_VALUE))
        );

        SeleccionarUsuario.getAccessibleContext().setAccessibleName("Peliculas alquiladas (Usuario Actual)");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    IMapeoObjetos mapo = new MapeoObjetos();
    private boolean notYet = true;
    
    
    private void usuaIdjComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_usuaIdjComboBoxItemStateChanged
        String aa = usuaIdjComboBox.getSelectedItem().toString();
        if (!" ".equals(aa)) {
            ArrayList<Usua> ListUsua = mapo.getUsua(aa);
            for (Usua usua : ListUsua) {
                SM.setUsuaSelected(usua);
                this.usuaNamejTex.setText(usua.nom);
                this.usuaApejTex.setText(usua.ape);
                this.usuaApe2jTex.setText(usua.ape2);
            }
        }
}//GEN-LAST:event_usuaIdjComboBoxItemStateChanged

    private void SeleccionarUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SeleccionarUsuarioActionPerformed
        try {                        
            new ConsultaPelisAlquiladas().setVisible(true);
        } catch (Exception e) {
        }
}//GEN-LAST:event_SeleccionarUsuarioActionPerformed

    private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated
        if (notYet) {

            notYet = false;
            try {
                SM.lastError = "";
                ArrayList<Usua> ListUsua = mapo.getUsua();
                usuaIdjComboBox.addItem(" ");
                for (Usua usua : ListUsua) {
                    usuaIdjComboBox.addItem(usua.id);
                }
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(null, "Ocurrio un error los datos no se pudieron cargar");
            }
        }
    }//GEN-LAST:event_formWindowActivated


    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton SeleccionarUsuario;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JTextField usuaApe2jTex;
    private javax.swing.JTextField usuaApejTex;
    private javax.swing.JComboBox usuaIdjComboBox;
    private javax.swing.JTextField usuaNamejTex;
    // End of variables declaration//GEN-END:variables
}
